/**
 * The main application class. An instance of this class is created by app.js when it
 * calls Ext.application(). This is the ideal place to handle application launch and
 * initialization details.
 */
Ext.define('CMS.Application', {
    extend: 'Ext.app.Application',

    name: 'CMS',

    views: [
        'CMS.views.login.LoginWin',
        'CMS.views.logup.LogupWinLink',
        'CMS.views.logup.LogupWinMain',
        'CMS.views.main.Main',
        'CMS.views.main.totalBill.totalBill',
        'CMS.views.main.totalBill.personalToolbar',
        'CMS.views.main.totalBill.personalGrid',
        'CMS.views.main.totalBill.billBarChart',
        'CMS.views.main.totalBill.Bar',
        'CMS.views.main.totalBill.billPieChart',
        'CMS.views.main.totalBill.billChart'
    ],

    quickTips: false,
    platformConfig: {
        desktop: {
            quickTips: true
        }
    },

    stores: [
        // TODO: add global / shared stores here
        'CMS.store.totalBill.personalStore'
    ],

    init: function() {
        var me = this;
        me.loadingScreen = Ext.getBody().mask('Loading', 'x-loadingscreen');
        me.loadingScreen.addCls('x-loadingscreen');
        Ext.dom.Helper.insertFirst(me.loadingScreen, {
            cls: 'x-loadingscreen-icon'
        });
    },

    launch: function () {
        // TODO - Launch the application
        var me = this;
        var task = new Ext.util.DelayedTask(function() {
            me.loadingScreen.fadeOut({
                duration: 1000,
                remove: true,
                listeners: {
                    afteranimate: function(el, startTime, eOpts) {
                        Ext.create({
                            xtype: 'LoginWin'
                        });
                    }
                }
            });
        });
        task.delay(2000);

    },

    onAppUpdate: function () {
        Ext.Msg.confirm('Application Update', 'This application has an update, reload?',
            function (choice) {
                if (choice === 'yes') {
                    window.location.reload();
                }
            }
        );
    }
});
